﻿using Maxi.Models.Banco;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;

namespace Maxi.Controllers
{
    public class BaseController : Controller
    {
        //protected override void OnException(ExceptionContext filterContext)
        //{
        //    base.OnException(filterContext);
        //    filterContext.ExceptionHandled = true;
        //    if (filterContext.HttpContext.Request.IsAjaxRequest())
        //    {
        //        var ex = filterContext.Exception;

        //        filterContext.RequestContext.HttpContext.Response.StatusCode = Convert.ToInt32(HttpStatusCode.InternalServerError);
        //        filterContext.Result = new JsonResult
        //        {
        //            JsonRequestBehavior = JsonRequestBehavior.AllowGet,
        //            ContentType = "application/json",
        //            Data = new
        //            {
        //                exceptionType = ex.GetType().ToString(),
        //                exceptionMessage = ex.Message,
        //                //exceptionStack = getExceptionMessage(ex)
        //            }
        //        };
        //    }
        //    else
        //    {
        //        var controllerName = filterContext.RouteData.Values["controller"];
        //        var actionName = filterContext.RouteData.Values["action"];
        //        Tb_LogErro erro = new Tb_LogErro()
        //        {
        //            Action = filterContext.RouteData.Values["action"].ToString(),
        //            Controller = filterContext.RouteData.Values["controller"].ToString(),
        //            Data = DateTime.Now,
        //            Exception = filterContext.Exception.Message,
        //            Browser = Request.Browser.Browser + " " + Request.Browser.Version,
        //            InnerException = filterContext.Exception.InnerException == null ? string.Empty : filterContext.Exception.InnerException.ToString()
        //        };
        //        Conexao con = new Conexao();
        //        con.Tb_LogErro.Add(erro);
        //        con.SaveChanges();
        //        //filterContext.HttpContext.Response.StatusCode = Convert.ToInt32(HttpStatusCode.Redirect);
        //        //filterContext.Result = new RedirectResult("~/Home/Index");
        //    }
        //}

        public JsonResult GetLanguage()
        {
            string allText = System.IO.File.ReadAllText(Server.MapPath("/Content/Tema/js/pt-br.json"));

            return Json(allText,JsonRequestBehavior.AllowGet);
        }
    }
}